﻿<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="../themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../themes/icon.css">
	<link rel="stylesheet" type="text/css" href="../demo.css">
	<script type="text/javascript" src="../jquery.min.js"></script>
	<script type="text/javascript" src="../jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../extend.js"></script>
    <script>
        var dataListCache = null;
        var dataCache = null;
        var appId = GetQueryString("moduleid");
        window.onresize=calSize;
        $(document).ready(function(){
            setData();
            calSize();

		});
        function setData(){
            $.get("../../api/user/list",function(data){
                if(data.Result==0){
                    dataListCache = JSON.parse(data.Data);
                    $('#userList').datagrid('loadData', dataListCache); 
                }
            },"json")
            .error(function(){
                $.messager.alert("错误","系统内部错误","error");
            })
            .complete(function() { 
            });
        }
        window.onresize=calSize;
        function calSize(){
            var height=window.parent.document.getElementById("mainFrame").clientHeight;
            var width=window.parent.document.getElementById("mainFrame").clientWidth;
            window.parent.document.getElementById(appId).height = height-35;
            $("#userList").datagrid({height:height-80,width:width-20});
            $("#toolbar").panel({width:width-20});
        }
        function loadDataCache(rowIndex, rowData) {
            dataCache = rowData;
        }

        function initVal(){
            $('#AutoId').val(dataCache.AutoId);
            $('#Flag').val(dataCache.Flag);
            $('#Code').textbox("setValue",dataCache.Code);
            $('#Name').textbox("setValue",dataCache.Name);
            $('#LastLogin').textbox("setValue",dataCache.LastLogin);
            if(dataCache.IsAdmin){
                document.getElementById("IsAdmin").checked = true;
            }else{
                document.getElementById("IsAdmin").checked = false;
            }
        }
        function createNewRecord(){
            dataCache = new Object();
            initVal();
            $('#editContent').window('open');
        }
        function editRecord(rowIndex, rowData) {
            dataCache = new Object();
            initVal();
            $('#editContent').window('open');
        }
        function chgPwd() {
            if (dataCache == null) {
                $.messager.alert("错误", "无法获取被编辑的对象", "error");
                return;
            }
            addTab(0, "修改密码[" + dataCache.Name + "]", "../chgpwd.html", "&uid="+dataCache.AutoId);
        }
        function submitChange(){
            if (dataCache == null) {
                $.messager.alert("错误", "无法获取被编辑的对象", "error");
                return;
            }
            showMask();
            dataCache.Flag = $("#Flag").val();
            dataCache.Code=$("#Code").textbox("getValue");
            dataCache.Name=$("#Name").textbox("getValue");
            dataCache.IsAdmin=document.getElementById("IsAdmin").checked;
            $.post("../../api/user/set",dataCache,function(response){
                if(response.Result==0){
                    dataCache = JSON.parse(response.Data);
                    if(dataCache.Flag!=1){
                        for(var i=0;i<dataListCache.length;i++){
                            if(dataListCache[i].AutoId == dataCache.AutoId){
                                dataListCache.splice(i,1);
                                break;
                            }
                        }
                    }
                    dataListCache.push(dataCache);
                    $('#userList').datagrid('loadData', dataListCache); 
                    $.messager.alert("信息","操作成功","info");
                    $('#editContent').window('close');
                }else{
                    $.messager.alert("错误",response.Message,"error");
                }
            })
            .error(function(){
                $.messager.alert("错误","系统内部错误","error");
            })
            .complete(function() { 
                hideMask();
            });
        }
        function boolFormatter(value,row,index){
            if(value){
                return "是";
            }else{
                return "否";
            }
        }
    </script>
<head>
<body>
	<div id="toolbar" class="easyui-panel" style="padding:1px;">
		<a href="#" class="easyui-linkbutton" data-options="onClick:createNewRecord,iconCls:'icon-edit',plain:true">新建</a>
		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">删除</a>
        <a href="#" class="easyui-linkbutton" data-options="onClick:chgPwd,iconCls:'icon-search',plain:true">重置密码</a>
	</div>
    <div style="margin:2px"></div>
    <table id="userList" class="easyui-datagrid"
        data-options="singleSelect:true,method:'get',onDblClickRow:editRecord,onClickRow:loadDataCache">
        <thead>
            <tr>
                <th data-options="field:'AutoId',hidden:true"></th>
                <th data-options="field:'Flag',hidden:true"></th>
                <th data-options="field:'Code',width:120,align:'right'">用户代号</th>
                <th data-options="field:'Name',width:120,align:'right'">用户名称</th>
                <th data-options="field:'IsAdmin',width:100,align:'right' ,formatter:boolFormatter">管理员</th>
                <th data-options="field:'LastLogin',width:300,align:'right'">最后登录时间</th>
            </tr>
        </thead>
    </table>
    <div id="editContent" class="easyui-window" title="编辑框" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:1000px;height:500px;padding:10px;">
        <div class="easyui-panel" style="padding:1px;width:100%">
            <a href="#" class="easyui-linkbutton" data-options="onClick:submitChange,iconCls:'icon-save',plain:true">保存</a>
            <a href="#" class="easyui-linkbutton" data-options="onClick:initVal,iconCls:'icon-no',plain:true">取消</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true,disabled:true">审核</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-back',plain:true,disabled:true">反审</a>
        </div>
        <div style="margin:2px"></div>
        <div id="editZone" class="easyui-panel" style="padding:10px;width:100%;height:400px">
            <table>
                <tr>
                    <td><input class="easyui-textbox" id="Code"  style="width:300px" data-options="label:'用户代号:',required:true"></td>
                    <td>&nbsp;</td>
                    <td><input class="easyui-textbox" id="Name"  style="width:300px" data-options="label:'用户名称:'"></td>
                </tr>
                <tr>
                    <td><input class="easyui-textbox" id="LastLogin" style="width:300px" data-options="disabled:true,label:'最后登录时间:'"></td>
                    <td>&nbsp;</td>
                    <td>管理员<input type="checkbox"  id="IsAdmin"/></td>
                </tr>
            </table>
            <div hidden>
                <p id="AutoId"></p>
                <p id="Flag"></p>
            </div>
        </div>
	</div>
</body>
</html>